home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: newsfeed.internetmci.com!anasaz!duane
- From: duane@anasazi.com (Duane Morse)
- Subject: Re: HELP - Passing strings to a DLL
- Message-ID: <DpKIsu.Gqn@anasazi.com>
- Sender: usenet@anasazi.com (News System)
- Organization: Anasazi Inc, Phoenix AZ USA
- References: <4kbbh2$r3c@hp_open.open.org>
- Date: Tue, 9 Apr 1996 00:02:43 GMT
-
- THayworth@open.org (Tina Hayworth) writes:
-
- >I am not an experienced C++ programmer, but I have taken a couple C
- >classes a few years ago. I need to write a simple DLL that will be called by
- >VB.
-
- >I found some sample code, wrote the program, and it worked - I thought I had
- >it all figured out. But if I try passing a pointer to a large string to a
- >function in the DLL, I get a GPF.
-
- >In the code below, if commarea is 40 bytes or less it works. If it is larger
- >I get a GPF. The actual string I need to pass is 11,452 bytes.
-
- >Can anyone tell me what I am doing wrong?
-
- >Here is the function I am calling:
-
- >int FAR PASCAL EciSync (char server[], char userid[], char passwd[],
- > char program[], char transid[], char *commarea, int
- >comsize)
- >---------------------------------------------------------------------------
- >Here is my DEF file:
-
- >LIBRARY ECIDLLL
-
- >EXETYPE WINDOWS
-
- >SEGMENTS
- > WEPSEG PRELOAD FIXED
-
- >CODE PRELOAD MOVEABLE DISCARDABLE
- >DATA PRELOAD MOVEABLE SINGLE
-
- >HEAPSIZE 5120
-
- >EXPORTS
- > WEP @1 RESIDENTNAME
- > EciSync @2
- >------------------------------------------------------------------------
- >Here is the Declaration in VB:
-
- >Declare Sub EciSync Lib "ecidll.dll" (ByVal S As String, ByVal U As String,
- >ByVal P As String, ByVal Pg As String, ByVal T As String, ByVal c As String,
- >ByVal S As Integer)
-
- I presume your DLL is returning data in commarea (c above). Did you
- preallocate the maximum amount of space that you might write into
- this area; for instance, Dim CommArea as String * 12000? Also,
- if you want to use this as a real VB string, EciSync should return
- the length of the string, so your calling routine can then do a
- Left(c, nLen) to extract the string.
- --
-
- Duane Morse e-mail: duane@anasazi.com
- (602) 861-7609; Phoenix, Arizona
-